package com.dream.oproject.base.service.impl;

import java.io.Serializable;
import java.util.List;

import org.springframework.stereotype.Service;

import com.dream.oproject.base.dao.IBaseDao;
import com.dream.oproject.base.dao.impl.BaseDao;
import com.dream.oproject.base.model.IdEntity;
import com.dream.oproject.base.service.IBaseService;
import com.dream.oproject.page.PageInfo;

/**
 * @author Administrator
 * @date 2011-9-11
 */

@Service("baseService")
public class BaseService<T extends IdEntity, PK extends Serializable> implements IBaseService<T, PK> {

	protected IBaseDao<T,PK> dao;
	
	public void setBaseDao(IBaseDao<T, PK> dao) {
		this.dao = dao;
	}
	
	public void setBaseDao(String daoName) {
		Class c;
		try {
			c = Class.forName(daoName);
			this.dao = (IBaseDao)c.newInstance();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		
	}
	 

	public int deleteObjectByPk(PK pk) {
		return dao.delete(pk);
	}

	public T getObjectByPK(PK pk) {
		return dao.get(pk);
	}

	public PageInfo getObjectListByPage(PageInfo pageInfo) {
		return dao.getObjectListByPage(pageInfo);
	}

	public T saveObject(T object) {
		dao.save(object);
		return object;
	}


}
